package com.example.field.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

//数据源实现
@Configuration
@ComponentScan({"com.example.field.field_common", "com.example.field.field_manage", "com.example.field.field_bigData", "com.example.field.field_analyse", "com.example.field.field_report"})
//自动扫描包，让指定包下的@RequestMapping注解生效,加入到iIOC容器，由IOC容器统一管理
@MapperScan({"com.example.field.field_common","com.example.field.manage", "com.example.field.bigData", "com.example.field.analyse" , "com.example.field.report"})
//自动扫描包
public class WebConfiguration
{
        @Value("${ALI_DOMAIN}")
        private String ALI_DOMAIN;
        @Value("${endpoint}")
        private String endpoint;

        @Value("${BUCKET_NAME}")
        private String bucketName;

        @Value("${accessKeyId}")
        private String accessKeyId;

        @Value("${accessKeySecret}")
        private String accessKeySecret;


        @Bean
        public CorsFilter corsFilter() {
                //允许跨域请求
                CorsConfiguration config = new CorsConfiguration();
                config.addAllowedOrigin("*");
                config.addAllowedHeader("*");
                config.addAllowedMethod("*");

                UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
                source.registerCorsConfiguration("/**", config);

                return new CorsFilter(source);
        }

}
